package demo1

import "fmt"

// 命令设计模式

type Command interface {
	Excute()
}

type StartReboot struct {
	mb *MotherBoard
}

func NewStartReboot(mb *MotherBoard) *StartReboot {
	return &StartReboot{mb: mb}
}

func (s *StartReboot) Excute() {
	s.mb.Start()
}

type StopReboot struct {
	mb *MotherBoard
}

func NewStopReboot(mb *MotherBoard) *StopReboot {
	return &StopReboot{mb: mb}
}

func (s *StopReboot) Excute() {
	s.mb.Stop()
}

type MotherBoard struct{}

func (m *MotherBoard) Start() {
	fmt.Println("starting")
}

func (m *MotherBoard) Stop() {
	fmt.Println("stop")
}

// 实现
type Box struct {
	button1 Command
	button2 Command
}

func NewBox(button1, button2 Command) *Box {
	return &Box{
		button1: button1,
		button2: button2,
	}
}

func (b *Box) Excute() {
	b.button1.Excute()
	b.button2.Excute()
}
